package com.visual.open.anpr.server.bootstrap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.net.Inet4Address;
import java.net.UnknownHostException;

@SpringBootApplication
public class OpenAnprApplication implements ApplicationListener<WebServerInitializedEvent> {

	private static final Logger log = LoggerFactory.getLogger(OpenAnprApplication.class);

	public static void main(String[] args) {
		SpringApplication.run(OpenAnprApplication.class, args);
	}

	@Override
	public void onApplicationEvent(WebServerInitializedEvent event) {
		try {
			// 获取IP
			String hostAddress = Inet4Address.getLocalHost().getHostAddress();
			// 获取端口号
			int port = event.getWebServer().getPort();
			// 获取应用名
			String applicationName = event.getApplicationContext().getApplicationName();
			// 打印 Knife4j文档地址
			log.info("项目启动启动成功！Knife4j接口文档地址: http://" + hostAddress + ":" + port + applicationName + "/doc.html");
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
	}
}
